import { SSOWebConfig } from '@mtfe/sso-web/lib/types';
import SSOWeb from '@mtfe/sso-web';

const {
  // REACT_APP_API_HOST: host,
  REACT_APP_SSO_ENV: env,
  REACT_APP_SSO_CLIENT_ID: clientId,
  // REACT_APP_SSO_PATH: path,
} = process.env;

if (!env || !clientId) {
  throw new Error('缺失 SSO 配置信息');
}

const lp = window.location.pathname;

export const ssoOption: SSOWebConfig = {
  clientId,
  accessEnv: ['production'].includes(env) ? 'product' : 'test',
  callbackUrl: `${lp}#/sso/callback`,
  schema: ['production'].includes(env) ? 'https' : 'http',
  sameSite: !['production'].includes(env),
};

export default SSOWeb(ssoOption);
